﻿package ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import components.MyButton;
import components.MyFrame;
import components.MyPanel;

import salesManagerLogic.MockSalesManagerLogic;
import vo.salesManager.BookAddPanelVO;
import vo.salesManager.BookModifyPanelVO;

import logicInterface.SalesManagerLogicInterface;
import main.Main;

public class BookModifyPanel extends MyPanel{
	
	private MyButton logoutButton;
	private MyButton returnbackButton;
	
	private JScrollPane modifybookpanelScrollPane;
	private JLabel pleasemodifybookLabel;
	private JLabel booknamemodifyLabel;
	private JLabel bookclassmodifyLabel;
	private JComboBox bookclassmodifyComboBox;
	private JLabel authormodifyLabel;
	private JTextField authormodifyField;
	private JLabel publishermodifyLabel;
	private JTextField publishermodifyField;
	private JLabel booknummodifylLabel;
	private JTextField booknummodifyTextField;
	private JLabel bookpricemodifyLabel;
	private JTextField bookpricemodifytTextField;
	private JLabel isbnLabel;
	private JTextField isbnField;
	private MyButton confirmmodifybookButton;

	
	protected void initComponent() {
		BookModifyPanelVO bmpvo=null;
		try {
			bmpvo = Main.getLogic().getBmpvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
		logoutButton = new MyButton("注销");
		returnbackButton = new MyButton("返回");
		logoutButton.setBounds(MyFrame.WIDTH-80,0, 80, 20);
		returnbackButton.setBounds(MyFrame.WIDTH-160,0, 80, 20);
		this.add(logoutButton);
		this.add(returnbackButton);
		
		modifybookpanelScrollPane = new JScrollPane(this);
	    modifybookpanelScrollPane.setBounds(300, 150, 500, 450);
	    modifybookpanelScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		pleasemodifybookLabel = new JLabel("请输入图书信息：");
		booknamemodifyLabel = new JLabel("图书名称："+bmpvo.getBookName());
		bookclassmodifyLabel = new JLabel("图书分类：");
		bookclassmodifyComboBox = new JComboBox(bmpvo.getTypes());
		bookclassmodifyComboBox.setSelectedIndex(bmpvo.getType());
		authormodifyLabel = new JLabel("作者：");
		authormodifyField = new JTextField();
		authormodifyField.setText(bmpvo.getAuthor());
		publishermodifyLabel = new JLabel("出版商：");
		publishermodifyField = new JTextField();
		publishermodifyField.setText(bmpvo.getPublisher());
		booknummodifylLabel = new JLabel("图书数量：");
		booknummodifyTextField = new JTextField(bmpvo.getBooknum());
		bookpricemodifyLabel = new JLabel("图书单价：");
		bookpricemodifytTextField = new JTextField(bmpvo.getBookprice());
		confirmmodifybookButton = new MyButton("确认修改");
        isbnLabel = new JLabel("ISBN：");
        isbnField = new JTextField(bmpvo.getIsbn());
		pleasemodifybookLabel.setBounds(10, 20, 120, 20);
	    booknamemodifyLabel.setBounds(20, 100, 300, 20);
	    bookclassmodifyLabel.setBounds(20, 140, 80, 20);
	    bookclassmodifyComboBox.setBounds(100, 140, 150, 25);
	    authormodifyLabel.setBounds(20, 180, 80, 20);
	    authormodifyField.setBounds(100, 180, 150, 25);
	    publishermodifyLabel.setBounds(20, 220, 80, 20);
	    publishermodifyField.setBounds(100,220, 150, 25);
	    booknummodifylLabel.setBounds(20, 260, 80, 20);
	    booknummodifyTextField.setBounds(100, 260, 150, 25);
	    bookpricemodifyLabel.setBounds(20, 300, 80, 20);
	    bookpricemodifytTextField.setBounds(100, 300, 150, 25);
	    isbnLabel.setBounds(20, 340, 80, 20);
		isbnField.setBounds(100, 340, 150, 25);
	    confirmmodifybookButton.setBounds(330, 140, 100, 40);
	    this.add(pleasemodifybookLabel);
	    this.add(booknamemodifyLabel);
	    this.add(bookclassmodifyLabel);
	    this.add(bookclassmodifyComboBox);
	    this.add(authormodifyLabel);
	    this.add(authormodifyField);
	    this.add(publishermodifyLabel);
	    this.add(publishermodifyField);
	    this.add(booknummodifylLabel);
	    this.add(booknummodifyTextField);
	    this.add(bookpricemodifyLabel);
	    this.add(bookpricemodifytTextField);
	    this.add(confirmmodifybookButton);
	    this.add(isbnField);
	    this.add(isbnLabel);
	    
	    logoutButton.setButtonAction("logout");
		returnbackButton.setButtonAction("toBookQuery");
		confirmmodifybookButton.setButtonAction("modifyBook");
	}


	@Override
	protected void updateVO() {
		BookModifyPanelVO bmpvo = null;
		try {
			bmpvo = Main.getLogic().getBmpvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		bmpvo.setType(bookclassmodifyComboBox.getSelectedIndex());
		bmpvo.setAuthor(authormodifyField.getText());
		bmpvo.setPublisher(publishermodifyField.getText());
		bmpvo.setBooknum(booknummodifyTextField.getText());
		bmpvo.setBookprice(bookpricemodifytTextField.getText());
		bmpvo.setIsbn(isbnField.getText());
		try {
			Main.getLogic().setBmpvo(bmpvo);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

}
